void finishStage(Map@ map, bool portal){
    map.showEffect("quest/party/clear");
    map.playSound("Party1/Clear");
    if(portal)
	   map.enablePortal("next00");
}

void giveExp(Players@ players, int exp){
    for(int i=0; i<players.getAmount(); i++)
        if(players[i].getHP() > 0)
            players[i].giveExp(exp);
}

void cleared(NPC@ npc){
    npc.addText("You all have cleared the quest for this stage. Use the portal to move to the next stage...");
    npc.sendNext();
    npc.end();
}

void npc(Player @player, NPC @npc) {
    int state = npc.getState();
    if(state == 0){                   
    npc.addText("Hello and welcome to the last stage! In this stage you must kill Alishar, but I warn you... He's strong! Good luck with killing him!");
    npc.sendNext();
    }
    else if(state == 1){ 
    if(player.getItemAmount(4001023) >= 1){
    npc.addText("You have cleared this stage!");
    npc.sendOK();
    player.giveItem(4001023, -1);
    finishStage(player.getMap(), true);
    giveExp(player.getMap().getPlayers(), 5950);
    player.getChannel().createEvent("lpqbonus", player.getParty());
    npc.end();
    }
    else{
    npc.addText("Sorry, you don't have the key.");
    npc.sendOK();
    npc.end();
}
}
}